package com.zcsy.manage.owner.controller.mall;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.druid.util.StringUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zcsy.commons.constants.Constants;
import com.zcsy.commons.constants.OwnerConstants;
import com.zcsy.commons.model.RequestJson;
import com.zcsy.commons.unique.UniqueNumberUtils;
import com.zcsy.commons.util.DateUtils;
import com.zcsy.commons.util.Globals;
import com.zcsy.manage.model.base.AppConfig;
import com.zcsy.manage.model.base.CellHouse;
import com.zcsy.manage.model.base.CellInfo;
import com.zcsy.manage.model.base.CommonImg;
import com.zcsy.manage.model.base.CommonToken;
import com.zcsy.manage.model.base.ShopInfo;
import com.zcsy.manage.model.mall.AdCategory;
import com.zcsy.manage.model.mall.AdInfo;
import com.zcsy.manage.model.mall.CouponDetail;
import com.zcsy.manage.model.mall.CouponInfo;
import com.zcsy.manage.model.mall.GoodsCategory;
import com.zcsy.manage.model.mall.GoodsCollection;
import com.zcsy.manage.model.mall.GoodsComment;
import com.zcsy.manage.model.mall.GoodsInfo;
import com.zcsy.manage.model.mall.GoodsSpecAttrNameValue;
import com.zcsy.manage.model.mall.GoodsSpecInfo;
import com.zcsy.manage.model.mall.GoodsSpecification;
import com.zcsy.manage.model.mall.OwnerAddress;
import com.zcsy.manage.model.system.User;
import com.zcsy.manage.owner.service.common.IOCommonTokenService;
import com.zcsy.manage.owner.service.system.IOUserService;
import com.zcsy.manage.service.base.IAppConfigService;
import com.zcsy.manage.service.base.ICellHouseService;
import com.zcsy.manage.service.base.ICellInfoService;
import com.zcsy.manage.service.base.IShopInfoService;
import com.zcsy.manage.service.mall.IAdCategoryService;
import com.zcsy.manage.service.mall.IAdInfoService;
import com.zcsy.manage.service.mall.ICouponDetailService;
import com.zcsy.manage.service.mall.ICouponInfoService;
import com.zcsy.manage.service.mall.IGoodsCategoryService;
import com.zcsy.manage.service.mall.IGoodsCollectionService;
import com.zcsy.manage.service.mall.IGoodsInfoService;
import com.zcsy.manage.service.mall.IOwnerAddressService;
import com.zcsy.manage.service.system.IUserService;

/**
 * @Title: mallController.java
 * @Package： com.zcsy.manage.owner.controller.mall
 * @Description: 商城控制层
 *
 * @author caiyinli 13277030520@163.com
 * @Copyright: 2015 武汉中财数元信息技术有限公司 All rights reserved.
 * @date 2016年7月8日
 * @version 1.0
 * @see JDK1.7.0_75
 * @since
 */
@Controller
@RequestMapping(value = "mall")
public class MallController {

	@Autowired
	private IGoodsInfoService goodsInfoService;

	@Autowired
	private IGoodsCategoryService goodsCategoryService;

	@Autowired
	private IGoodsCollectionService goodsCollectionService;

	@Autowired
	private IOCommonTokenService commonTokenService;

	@Autowired
	private IOUserService ouserService;

	@Autowired
	private ICouponInfoService couponInfoService;

	@Autowired
	private ICouponDetailService couponDetailService;

	@Autowired
	private IUserService userService;

	@Autowired
	private IShopInfoService shopInfoService;

	@Autowired
	private IOwnerAddressService ownerAddressService;

	@Autowired
	private ICellInfoService cellInfoService;

	@Autowired
	private ICellHouseService cellHouseService;

	@Autowired
	private IAdCategoryService adCategoryService;

	@Autowired
	private IAdInfoService adInfoService;

	@Autowired
	private IAppConfigService appConfigService;

	/**
	 * @Method: collectionList
	 * @Description 商品收藏列表接口
	 * @param token
	 * @return name String 商品名
	 * @return logo String 图片
	 * @return marketPrice String 原价
	 * @return price String 现价
	 * @return goodsCategoryName String 分类
	 * @author liuziyu liuziyuwri@foxmail.com
	 * @date 2016年7月8日
	 * @see
	 */
	@RequestMapping(value = "collectionList")
	@ResponseBody
	public RequestJson collectionList(String token) {

		RequestJson result = new RequestJson();

		CommonToken commonToken = commonTokenService.selectByToken(token);
		// 根据token查询登录名
		String loginname = commonToken.getAccount();
		// 根据登录名查询用户
		User user = ouserService.selectByLoginName(loginname);
		// 根据用户查询业主ID
		String userID = user.getId();

		// 根据业主id联表查询收藏列表
		List<GoodsCollection> goodsCollection = goodsCollectionService
				.getGoodsCollectionByOwnerId(userID);

		if (goodsCollection != null && goodsCollection.size() > 0) {
			result.setSuccess(true);
			result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
			result.setMsg("数据获取成功！");
			result.setObj(goodsCollection);
		} else {
			result.setSuccess(false);
			result.setResultCode(OwnerConstants.RESULT_CODE_FALSE);
			result.setMsg("未查询到收藏商品！");

		}

		return result;
	}

	/**
	 * @Method: shopCoupon
	 * @Description 店铺优惠券列表
	 * @param shopId
	 *            店铺id
	 * @return result 店铺及平台优惠券列表
	 * @author yangfan 373188993@qq.com
	 * @date 2016年7月11日
	 * @see
	 */
	@RequestMapping(value = "shopCoupon")
	@ResponseBody
	public RequestJson shopCoupon(String shopId, Integer pNo ,String token) {

		RequestJson result = new RequestJson();

		try {
		    // 指定默认为首页
		    if (pNo == null || pNo < OwnerConstants.PAGE_NO) {
		        pNo = OwnerConstants.PAGE_NO;
		    }
		    
		    CommonToken commonToken = commonTokenService.selectByToken(token);
		    // 根据token查询登录名
		    String loginname = commonToken.getAccount();
		    
		    CouponDetail couponDetail = new CouponDetail();
		    couponDetail.setUserAccount(loginname);
		    
		    // 此处添加PageHelper将会走拦截器，进行分页，分页方法只针对紧跟着PageHelper的查询方法有效
		    PageHelper.startPage(pNo, Constants.PAGE_SIZE);
		    
		    List<CouponInfo> couponInfoList = couponInfoService
		        .getCouponInfoByShopId(shopId);
		    if (!couponInfoList.isEmpty()) {
		        // 循环判断每一张优惠券优惠券是否被领取，已领取isGot置1，未领取置0
		        for (CouponInfo record : couponInfoList) {
		            couponDetail.setCouponId(record.getId());
		            List<CouponDetail> couponDetailList = couponDetailService
		                .selectCouponDetailByKeyword(couponDetail);
		            if (!couponDetailList.isEmpty()) {
		                record.setIsGot(OwnerConstants.COUPON_IS_GOT);
		            } else {
		                record.setIsGot(OwnerConstants.COUPON_IS_NOT_GOT);
		            }
		        }
		        PageInfo<CouponInfo> couponInfoListP = new PageInfo<CouponInfo>(
		            couponInfoList);
		        result.setSuccess(true);
		        result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
		        result.setMsg("获取平台优惠券列表成功！");
		        result.setObj(couponInfoListP);
		    } else {
		        result.setResultCode(OwnerConstants.RESULT_EXCEPTION_FALSE);
		        result.setMsg("无数据！");
		    }
        } catch (Exception e) {
            result.setSuccess(false);
            result.setResultCode(OwnerConstants.RESULT_EXCEPTION_FALSE);
            result.setMsg("网络异常");
        }

		return result;

	}

	/**
	 * @Method: platformCoupon
	 * @Description 平台优惠券
	 * @param token
	 * @return result 店铺及平台优惠券列表
	 * @author yangfan 373188993@qq.com
	 * @date 2016年7月11日
	 * @see
	 */
	@RequestMapping(value = "platformCoupon")
	@ResponseBody
	public RequestJson platformCoupon(String token) {

		RequestJson result = new RequestJson();

		try {
		    CommonToken commonToken = commonTokenService.selectByToken(token);
		    // 根据token查询登录名
		    String loginname = commonToken.getAccount();
		    
		    CouponDetail couponDetail = new CouponDetail();
		    couponDetail.setUserAccount(loginname);
		    
		    List<CouponInfo> couponInfoList = couponInfoService
		        .getPlatformCouponInfo();
		    
		    if (!couponInfoList.isEmpty()) {
		        // 循环判断每一张平台优惠券是否被领取，已领取isGot置1，未领取置0
		        for (CouponInfo record : couponInfoList) {
		            couponDetail.setCouponId(record.getId());
		            List<CouponDetail> couponDetailList = couponDetailService
		                .selectCouponDetailByKeyword(couponDetail);
		            if (!couponDetailList.isEmpty()) {
		                record.setIsGot(OwnerConstants.COUPON_IS_GOT);
		            } else {
		                record.setIsGot(OwnerConstants.COUPON_IS_NOT_GOT);
		            }
		        }
		        result.setSuccess(true);
		        result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
		        result.setMsg("获取平台优惠券列表成功！");
		        result.setObj(couponInfoList);
		    } else {
		        result.setResultCode(OwnerConstants.RESULT_EXCEPTION_FALSE);
		        result.setMsg("无数据！");
		    }
        } catch (Exception e) {
            result.setSuccess(false);
            result.setResultCode(OwnerConstants.RESULT_EXCEPTION_FALSE);
            result.setMsg("网络异常");
        }

		return result;
	}

	/**
	 * @Description 获取抢购中秒杀商品列表
	 * @param pNo
	 * @return
	 * @author luoyzh 823884124@qq.com
	 * @data 2016年7月12日
	 */
	@RequestMapping(value = "getMsGoodsList")
	@ResponseBody
	public RequestJson getMsGoodsList(Integer pNo) {
		RequestJson result = new RequestJson();
		// 指定默认为首页
		if (pNo == null || pNo < OwnerConstants.PAGE_NO) {
			pNo = OwnerConstants.PAGE_NO;
		}
		// 此处添加PageHelper将会走拦截器，进行分页，分页方法只针对紧跟着PageHelper的查询方法有效
		PageHelper.startPage(pNo, Constants.PAGE_SIZE);

		List<GoodsInfo> secKillGoodsList = goodsInfoService.getMsGoodsList();
		if(!CollectionUtils.isEmpty(secKillGoodsList)) {
		    for (GoodsInfo goodsInfo : secKillGoodsList) {
		        goodsInfo.setLogo(Globals.getImageUrl() + goodsInfo.getLogo());
		    }
		}
		PageInfo<GoodsInfo> secKillGoodsListP = new PageInfo<GoodsInfo>(secKillGoodsList);
		if (!secKillGoodsList.isEmpty() && (secKillGoodsList.size() > 0)) {
			result.setSuccess(true);
			result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
			result.setMsg("获取商品列表成功！");
			result.setObj(secKillGoodsListP);
		} else {
			result.setResultCode(OwnerConstants.RESULT_EXCEPTION_FALSE);
			result.setMsg("获取商品列表失败！");
		}
		return result;
	}

	/**
	 * @Description 获取即将开始秒杀商品列表
	 * @param pNo
	 * @return
	 * @author luoyzh 823884124@qq.com
	 * @data 2016年7月12日
	 */
	@RequestMapping(value = "getwaitMsGoodsList")
	@ResponseBody
	public RequestJson getWaitMsGoodsList(Integer pNo) {
		RequestJson result = new RequestJson();
		// 指定默认为首页
		if (pNo == null || pNo < OwnerConstants.PAGE_NO) {
			pNo = OwnerConstants.PAGE_NO;
		}
		// 此处添加PageHelper将会走拦截器，进行分页，分页方法只针对紧跟着PageHelper的查询方法有效
		PageHelper.startPage(pNo, Constants.PAGE_SIZE);
		List<GoodsInfo> waitMsGoodsList = goodsInfoService.getWaitMsGoodsList();
		PageInfo<GoodsInfo> waitMsGoodsListP = new PageInfo<GoodsInfo>(
				waitMsGoodsList);
		if (!waitMsGoodsList.isEmpty() && (waitMsGoodsList.size() > 0)) {
			result.setSuccess(true);
			result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
			result.setMsg("获取商品列表成功！");
			result.setObj(waitMsGoodsListP);
		} else {
			result.setResultCode(OwnerConstants.RESULT_EXCEPTION_FALSE);
			result.setMsg("获取商品列表失败！");
		}
		return result;
	}

	/**
	 * @Method: getCoupon
	 * @Description 优惠券领取接口
	 * @param token
	 *            标记 couponId 优惠券id imei 手机imei码
	 * @return
	 * @author yangfan 373188993@qq.com
	 * @date 2016年7月10日
	 * @see
	 */
	@RequestMapping(value = "getCoupon")
	@ResponseBody
	public synchronized RequestJson getCoupon(String token, String couponId, String imei) {

		RequestJson result = new RequestJson();
		CouponInfo couponInfo = null;
		CouponDetail couponDetailWithCountNumber = null;
        try {
            // 根据优惠券id获取优惠券信息
            couponInfo = couponInfoService.selectByPrimaryKey(couponId);
            
            //获取当前时间的字符串
            String now = DateUtils.formatDate(new Date());
            int resultOne = now.compareTo(couponInfo.getBeginDate());
            int resultTwo = couponInfo.getEndDate().compareTo(now);
           
            //判断当前时间是否在领取优惠券时间段内
            int resultTotal = 0;
            if (!( resultOne*resultTwo > resultTotal || resultOne*resultTwo == resultTotal)) {
                result.setSuccess(false);
                result.setResultCode(OwnerConstants.RESULT_CODE_FALSE);
                result.setMsg("您要领取的优惠券不在领取时间范围内！");
                return result;
            }
            
            // 根据token查询登录名
            CommonToken commonToken = commonTokenService.selectByToken(token);
            String loginname = commonToken.getAccount();
            
            // 根据登录名查询用户信息
            User user = userService.selectByLoginName(loginname);
            
            //判断该token是否领取了该优惠券
            if(couponDetailService.selectByUserAccountAndCouponId(couponId, loginname) != null) {
                result.setSuccess(false);
                result.setResultCode(OwnerConstants.RESULT_CODE_FALSE);
                result.setMsg("您已领取了该优惠券！");
                return result;
            }

            
            //获取领取优惠券的数量
            couponDetailWithCountNumber = couponDetailService.getCountNumerBycouponId(couponId);

            //领取数量少于总发放数量则可以领取
            if(couponDetailWithCountNumber.getCountNumber() < couponInfo.getCount()) {
                // 生成18位id
                String id = UniqueNumberUtils.get18UniqueNumber();
                
                // 添加领取优惠券信息
                CouponDetail couponDetail = new CouponDetail();
                couponDetail.setId(id);
                couponDetail.setCouponId(couponId);
                couponDetail.setState(OwnerConstants.COUPON_IS_SEND);
                couponDetail.setPhone(user.getPhone());
                couponDetail.setImei(imei);
                couponDetail.setUserAccount(loginname);
                Date time = DateUtils.stringToDate(couponInfo.getUseEndDate());
                couponDetail.setExpireTime(time);
                couponDetail.setCreateTime(DateUtils.gettimestamp());
                
                // 插入数据，1:成功 0:失败
                int flag = couponDetailService.insert(couponDetail);
                
                if (flag == OwnerConstants.INSERT_SUCCESS) {
                    result.setSuccess(true);
                    result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
                    result.setMsg("优惠券领取成功！");
                } else {
                    result.setSuccess(false);
                    result.setResultCode(OwnerConstants.RESULT_CODE_FALSE);
                    result.setMsg("网络异常！");
                }
            } else {
                result.setSuccess(false);
                result.setResultCode(OwnerConstants.RESULT_CODE_FALSE);
                result.setMsg("优惠券已被抢完了！");
            }
            
        } catch (Exception e) {
            e.printStackTrace();
            result.setSuccess(false);
            result.setResultCode(OwnerConstants.RESULT_EXCEPTION_FALSE);
            result.setMsg("网络异常");
        }

        return result;
    }

	/**
	 * @Method: getShopList
	 * @Description 获取店铺列表
	 * @param shopName
	 *            店铺名
	 * @return result 店铺列表
	 * @author yangfan 373188993@qq.com
	 * @date 2016年7月10日
	 * @see
	 */
	@RequestMapping(value = "getShopList")
	@ResponseBody
	public RequestJson getShopList(String shopName, Integer pNo,String shopCategoryId, String cellId) {

		RequestJson result = new RequestJson();
		ShopInfo shopInfo = new ShopInfo();

		try {
		    // 指定默认为首页
		    if (pNo == null || pNo < OwnerConstants.PAGE_NO) {
		        pNo = OwnerConstants.PAGE_NO;
		    }
		    
		    if (null != shopName && "" != shopName) {
		        shopInfo.setName(shopName);
		    }
		    
		    shopInfo.setCellId(cellId);
		    
		    if (!StringUtils.isEmpty(shopCategoryId)) {
		        shopInfo.setShopCategoryId(shopCategoryId);
		    }
		    
		    shopInfo.setState(Constants.SHOP_STATE_NORMAL);
		    
		    // 此处添加PageHelper将会走拦截器，进行分页，分页方法只针对紧跟着PageHelper的查询方法有效
		    PageHelper.startPage(pNo, Constants.PAGE_SIZE);
		    List<ShopInfo> shopInfoList = shopInfoService.getShopList(shopInfo);
		    if (CollectionUtils.isNotEmpty(shopInfoList)) {
		        for (ShopInfo item : shopInfoList) {
		            item.setLogo(Globals.getImageUrl() + item.getLogo());
		        }
		    }
		    PageInfo<ShopInfo> shopInfoListP = new PageInfo<ShopInfo>(shopInfoList);
		    if (!shopInfoList.isEmpty()) {
		        result.setSuccess(true);
		        result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
		        result.setMsg("获取店铺列表成功！");
		        result.setObj(shopInfoListP);
		    } else {
		        result.setSuccess(false);
		        result.setResultCode(OwnerConstants.RESULT_CODE_FALSE);
		        result.setMsg("未查询到店铺信息！");
		    }
        } catch (Exception e) {
            e.printStackTrace();
            result.setSuccess(false);
            result.setResultCode(OwnerConstants.RESULT_EXCEPTION_FALSE);
            result.setMsg("网络异常");
        }
		return result;
	}

	/**
	 * @Method: getShopInfo
	 * @Description 获取店铺基本信息
	 * @param shopId
	 *            店铺id
	 * @return result 店铺基本信息
	 * @author yangfan 373188993@qq.com
	 * @date 2016年7月10日
	 * @see
	 */
	@RequestMapping(value = "getShopInfo")
	@ResponseBody
	public RequestJson getShopInfo(String shopId) {

		RequestJson result = new RequestJson();

		try {
		    ShopInfo shopInfo = shopInfoService.selectByPrimaryKey(shopId);
		    
		    if (shopInfo != null && shopInfo != null) {
		        result.setSuccess(true);
		        result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
		        result.setMsg("获取店铺基本信息成功！");
		        result.setObj(shopInfo);
		    } else {
		        result.setSuccess(false);
		        result.setResultCode(OwnerConstants.RESULT_EXCEPTION_FALSE);
		        result.setMsg("获取店铺基本信息失败！");
		    }
		    
        } catch (Exception e) {
            result.setSuccess(false);
            result.setResultCode(OwnerConstants.RESULT_EXCEPTION_FALSE);
            result.setMsg("网络异常");
        }
		return result;
	}

	/**
	 * @Method: collectionAddRemove
	 * @Description 商品收藏/取消收藏接口
	 * @param GoodsId
	 * @param token
	 * @return
	 * @author liuziyu liuziyuwri@foxmail.com
	 * @date 2016年7月8日
	 * @see
	 */
	@RequestMapping(value = "collectionAddRemove")
	@ResponseBody
	public RequestJson collectionAddRemove(String goodsId, String token) {

		RequestJson result = new RequestJson();

		CommonToken commonToken = commonTokenService.selectByToken(token);
		// 根据token查询登录名
		String loginname = commonToken.getAccount();
		// 根据登录名查询用户
		User user = ouserService.selectByLoginName(loginname);
		// 根据用户查询业主ID
		String ownerId = user.getId();

		// 判断商品是否已经收藏
		GoodsCollection goodsCollection = goodsCollectionService
				.getGoodsCollectionByOwnerIdAndGoodsId(ownerId, goodsId);
		// 已收藏过该商品，操作为取消收藏
		if (goodsCollection != null) {
			try {
				goodsCollectionService.deleteByOwnerIdAndGoodsId(ownerId,
						goodsId);
				result.setSuccess(true);
				result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
				result.setMsg("取消收藏商品成功！");
			} catch (Exception e) {
				result.setSuccess(false);
				result.setResultCode(OwnerConstants.RESULT_CODE_FALSE);
				result.setMsg("取消收藏失败！");
			}
			// 未收藏此商品，操作为添加收藏
		} else {
			goodsCollection = new GoodsCollection();
			goodsCollection.setId(UniqueNumberUtils.get18UniqueNumber());
			goodsCollection.setOwnerId(ownerId);
			goodsCollection.setGoodsId(goodsId);
			goodsCollection.setCollectionTime(DateUtils.gettimestamp());
			try {
				goodsCollectionService.insertCollection(goodsCollection);
				result.setSuccess(true);
				result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
				result.setMsg("收藏商品成功！");
			} catch (Exception e) {
				result.setSuccess(false);
				result.setResultCode(OwnerConstants.RESULT_CODE_FALSE);
				result.setMsg("添加收藏失败！");
			}
		}

		return result;
	}

	/**
	 * @Method: showAddress
	 * @Description 地址列表接口
	 * @param token
	 * @return
	 * @author liuziyu liuziyuwri@foxmail.com
	 * @date 2016年7月12日
	 * @see
	 */
	@RequestMapping(value = "showAddress")
	@ResponseBody
	public RequestJson showAddress(String token) {

		RequestJson result = new RequestJson();

		CommonToken commonToken = commonTokenService.selectByToken(token);
		// 根据token查询登录名
		String loginname = commonToken.getAccount();
		// 根据登录名查询用户
		User user = ouserService.selectByLoginName(loginname);
		// 根据用户查询业主ID
		String OwnerId = user.getId();

		List<OwnerAddress> ownerAddress = ownerAddressService
				.getOwnerAddressByOwnerId(OwnerId);

		// 查找详细地址
		Iterator<OwnerAddress> iterator = ownerAddress.iterator();
		while (iterator.hasNext()) {
			OwnerAddress address = (OwnerAddress) iterator.next();
			String cellId = address.getCellId();
			String houseId = address.getHouseId();
			CellInfo cell = cellInfoService.selectByPrimaryKey(cellId);
			CellHouse house = cellHouseService.selectByPrimaryKey(houseId);
			StringBuffer detailAddress = new StringBuffer();
			if (cell != null && house != null) {
				address.setProvinceName(cell.getProvinceName());
				address.setCityName(cell.getCityName());
				address.setAreaName(cell.getAreaName());
				address.setCellName(house.getCellName());
				address.setRegionName(house.getRegionName());
				address.setBuildingName(house.getBuildingName());
				address.setUnitName(house.getUnitName());
				address.setHouseName(house.getName());
				detailAddress.append(cell.getProvinceName())
						.append(cell.getCityName()).append(cell.getAreaName())
						.append(house.getCellName())
						.append(house.getRegionName())
						.append(house.getBuildingName())
						.append(house.getUnitName()).append(house.getName());
				address.setDetailAddress(detailAddress.toString());

			} else {
				continue;
			}

		}

		if (ownerAddress.isEmpty()) {
			result.setSuccess(false);
			result.setResultCode(OwnerConstants.RESULT_CODE_FALSE);
			result.setMsg("未查询到收货地址！");
		} else {
			result.setSuccess(true);
			result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
			result.setMsg("获得收货地址成功！");
			result.setObj(ownerAddress);

		}

		return result;
	}

	/**
	 * @Method: addEditAndSetDefaultAddress
	 * @Description 新增、编辑地址，设为默认地址
	 * @param token
	 * @param addressId
	 *            地址id，为空时增加地址，不为空时编辑地址
	 * @param defaultFlag
	 *            1为默认地址，0为普通地址
	 * @param cellId
	 *            用户的当前小区id
	 * @param regionId
	 *            区域id
	 * @param buildingId
	 *            楼栋id
	 * @param unitId
	 *            单元id
	 * @param houseId
	 *            房屋id
	 * @param recepientName
	 *            收货人
	 * @param recepientPhone收货电话
	 * @return
	 * @author liuziyu liuziyuwri@foxmail.com
	 * @date 2016年7月13日
	 * @see
	 */
	@RequestMapping(value = "addEditAndSetDefaultAddress")
	@ResponseBody
	public RequestJson addEditAndSetDefaultAddress(String token,
			String addressId, Integer defaultFlag, String cellId,
			String regionId, String buildingId, String unitId, String houseId,
			String recepientName, String recepientPhone) {

		RequestJson result = new RequestJson();

		CommonToken commonToken = commonTokenService.selectByToken(token);
		// 根据token查询登录名
		String loginname = commonToken.getAccount();
		// 根据登录名查询用户
		User user = ouserService.selectByLoginName(loginname);
		// 根据用户查询业主ID
		String ownerId = user.getId();

		OwnerAddress newAddress = new OwnerAddress();
		newAddress.setRegionId(regionId);
		newAddress.setBuildingId(buildingId);
		newAddress.setUnitId(unitId);
		newAddress.setHouseId(houseId);
		newAddress.setRecepientName(recepientName);
		newAddress.setRecepientPhone(recepientPhone);

		// 查询当前小区信息
		CellInfo cell = cellInfoService.selectByPrimaryKey(cellId);
		CellHouse house = cellHouseService.selectByPrimaryKey(houseId);
		StringBuffer detailAddress = new StringBuffer();
		detailAddress.append(cell.getProvinceName()).append(cell.getCityName())
				.append(cell.getAreaName()).append(house.getCellName())
				.append(house.getRegionName()).append(house.getBuildingName())
				.append(house.getUnitName()).append(house.getName());
		newAddress.setDetailAddress(detailAddress.toString());

		// 增加地址
		if (addressId == null) {
			newAddress.setId(UniqueNumberUtils.get18UniqueNumber());
			newAddress.setOwnerId(ownerId);
			newAddress.setCellId(cellId);
			newAddress.setProvinceId(cell.getProvinceId().toString());
			newAddress.setCityId(cell.getCityId().toString());
			newAddress.setAreaId(cell.getAreaId().toString());

			// 设置为默认地址
			if (defaultFlag == OwnerConstants.DEFAULT_ADDRESS) {
				// 将业主的默认地址设为普通地址
				ownerAddressService.updateDefaultFlagToZero(ownerId);
				// 将新增地址设为默认地址
				newAddress.setDefaultFlag(OwnerConstants.DEFAULT_ADDRESS);
			} else {
				newAddress.setDefaultFlag(OwnerConstants.NOT_DEFAULT_ADDRESS);
			}
			try {
				ownerAddressService.insertAddress(newAddress);
				result.setSuccess(true);
				result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
				result.setMsg("添加收货地址成功！");
				result.setObj(newAddress);
			} catch (Exception e) {
				e.printStackTrace();
				result.setSuccess(false);
				result.setResultCode(OwnerConstants.RESULT_CODE_FALSE);
				result.setMsg("添加收货地址失败！");
			}

			// 编辑地址
		} else {
			newAddress.setId(addressId);
			// 设置为默认地址
			if (defaultFlag == OwnerConstants.DEFAULT_ADDRESS) {
				// 将业主的默认地址设为普通地址
				ownerAddressService.updateDefaultFlagToZero(ownerId);
				// 将新增地址设为默认地址
				newAddress.setDefaultFlag(OwnerConstants.DEFAULT_ADDRESS);
			} else {
				newAddress.setDefaultFlag(OwnerConstants.NOT_DEFAULT_ADDRESS);
			}
			ownerAddressService.updateAddress(newAddress);
			result.setSuccess(true);
			result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
			result.setMsg("编辑收货地址成功！");
			result.setObj(newAddress);
		}
		return result;
	}

    /**
     * @Method: deleteAddress
     * @Description 删除收货地址接口
     * @param ownerAddressId
     *            收货地址id
     * @return
     * @author yangfan 373188993@qq.com
     * @date 2016年8月9日
     * @see
     */
    @RequestMapping(value = "deleteAddress")
    @ResponseBody
    public RequestJson deleteAddress(String ownerAddressId, String token) {

        RequestJson result = new RequestJson();
        
        try {
            result = commonTokenService.OrderInteractState(token, result);
            if (result.isSuccess()) {
                int flag = ownerAddressService.deleteByPrimaryKey(ownerAddressId);
                if (flag == OwnerConstants.DELETE_FALSE) {
                    result.setSuccess(false);
                    result.setResultCode(OwnerConstants.RESULT_CODE_FALSE);
                    result.setMsg("删除收货地址失败！");
                } else {
                    result.setSuccess(true);
                    result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
                    result.setMsg("删除收货地址成功！");
                }
            } else {
                result.setSuccess(false);
                result.setResultCode(OwnerConstants.RESULT_CODE_FALSE);
                result.setMsg("网络异常！");
            }
        } catch (Exception e) {
            result.setSuccess(false);
            result.setResultCode(OwnerConstants.RESULT_EXCEPTION_FALSE);
            result.setMsg("网络异常");
        }
        return result;
    }

	/**
	 * @Description 获取实时推荐商品列表<br>
	 * 
	 * @return 返回实时推荐商品列表
	 * @author caiyinli 13277030520@163.com
	 * @date 2016年7月13日
	 * @see
	 */
	@RequestMapping(value = "getRecommendGoods")
	@ResponseBody
	public RequestJson getRecommendGoods(String cellId) {

		RequestJson result = new RequestJson();

		try {
			// 精品
			AdCategory adCategory = adCategoryService
					.selectByValue("recommend");
			List<AdInfo> adInfos = new ArrayList<AdInfo>();
			if (adCategory != null) {
				adInfos = adInfoService
						.selectByAdCategoryId(adCategory.getId(),cellId);
				if (CollectionUtils.isNotEmpty(adInfos)) {
					for (AdInfo adInfo : adInfos) {
						adInfo.setImg(Globals.getImageUrl() + adInfo.getImg());
					}
				}
				result.setSuccess(true);
				result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
				result.setMsg("数据获取成功！");
				result.setObj(adInfos);
			}
		} catch (Exception e) {
			result.setSuccess(false);
			result.setResultCode(OwnerConstants.RESULT_CODE_FALSE);
			result.setMsg("数据获取失败！");
		}
		return result;
	}

	/**
	 * @Description 获取商品搜索列表
	 * @param name
	 *            商品名字（模糊查询）
	 * @param sortType
	 *            排序方式(0=按推荐度逆序排列(综合)，1=按销量逆序、推荐度逆序排列，2=按价格逆序、推荐度逆序排列，3=按价格正序、
	 *            推荐度逆序排列，4=不做排序)
	 * @param pNo
	 *            页数
	 * @return 商品信息列表
	 * @author luoyzh 823884124@qq.com
	 * @data 2016年7月13日
	 */
	@RequestMapping(value = "getSearchGoodsList")
	@ResponseBody
	public RequestJson getSearchGoodsList(String name, Integer sortType,
			Integer pNo, String goodsCategoryId, String shopId, String cellId) {
		RequestJson result = new RequestJson();
		if (goodsCategoryId == "") {
			goodsCategoryId = null;
		}
		if (cellId == "") {
			cellId = null;
		}
		if (shopId == "") {
			shopId = null;
		}

		if (sortType == null
				|| sortType < OwnerConstants.GOODS_SEARCH_SORT_TYPE) {
			sortType = OwnerConstants.GOODS_SEARCH_SORT_TYPE;
		}
		// 指定默认为首页
		if (pNo == null || pNo < OwnerConstants.PAGE_NO) {
			pNo = OwnerConstants.PAGE_NO;
		}

		try {
			GoodsInfo goodsInfo = new GoodsInfo();
			goodsInfo.setName(name);
			goodsInfo.setShopId(shopId);
			goodsInfo.setSortType(sortType);
			goodsInfo.setGoodsCategoryId(goodsCategoryId);
			String[] shopIds = goodsInfoService.getShopIdsByCellId(cellId);
			// 此处添加PageHelper将会走拦截器，进行分页，分页方法只针对紧跟着PageHelper的查询方法有效
			PageHelper.startPage(pNo, Constants.PAGE_SIZE);
			List<GoodsInfo> goodsinfoList = goodsInfoService
					.getSearchGoodsList(goodsInfo, shopIds);
			PageInfo<GoodsInfo> goodsinfoListP = new PageInfo<GoodsInfo>(
					goodsinfoList);
			if (!goodsinfoList.isEmpty()) {
				result.setSuccess(true);
				result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
				result.setMsg("获取商品列表成功！");
				result.setObj(goodsinfoListP);
			} else {
				result.setSuccess(false);
				result.setResultCode(OwnerConstants.RESULT_EXCEPTION_FALSE);
				result.setMsg("无数据！");
			}
		} catch (Exception e) {
			result.setSuccess(false);
			result.setResultCode(OwnerConstants.RESULT_CODE_FALSE);
			result.setMsg("数据获取失败！");
		}
		return result;
	}

	/**
	 * @Description 获取商品一二级分类
	 * @return 商品一二级分类列表
	 */
	@RequestMapping(value = "getGoodsCategorysList")
	@ResponseBody
	public RequestJson getGoodsCategorysList() {
		RequestJson result = new RequestJson();
//		try {
			List<GoodsCategory> categoryList = goodsInfoService
					.getGoodsCategorysList();
			if (!categoryList.isEmpty()) {
				result.setSuccess(true);
				result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
				result.setMsg("获取商品分类成功！");
				result.setObj(categoryList);
			} else {
				result.setSuccess(false);
				result.setResultCode(OwnerConstants.RESULT_EXCEPTION_FALSE);
				result.setMsg("无数据！");
			}
//		} catch (Exception e) {
//			result.setSuccess(false);
//			result.setResultCode(OwnerConstants.RESULT_CODE_FALSE);
//			result.setMsg("数据获取失败！");
//		}
		return result;
	}

	/**
	 * @Method: shopGoodsCategory
	 * @Description 获取商品分类信息（商品两级分类）
	 * @param shopId
	 *            店铺id
	 * @return result
	 * @author yangfan 373188993@qq.com
	 * @date 2016年7月12日
	 * @see
	 */
	@RequestMapping(value = "shopGoodsCategory")
	@ResponseBody
	public RequestJson shopGoodsCategory(String shopId) {

		RequestJson result = new RequestJson();

		try {
		    List<GoodsCategory> goodsCategory = goodsCategoryService.selectCategoryByShopId(shopId);
		    
		    if (!goodsCategory.isEmpty()) {
		        result.setSuccess(true);
		        result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
		        result.setMsg("获取商品分类信息成功！");
		        result.setObj(goodsCategory);
		    } else {
		        result.setSuccess(false);
		        result.setResultCode(OwnerConstants.RESULT_EXCEPTION_FALSE);
		        result.setMsg("无数据！");
		    }
        } catch (Exception e) {
            result.setSuccess(false);
            result.setResultCode(OwnerConstants.RESULT_EXCEPTION_FALSE);
            result.setMsg("网络异常");
        }
		return result;
	}

	/**
	 * @Description 获取商品信息详情
	 * @param goodsId
	 *            商品id
	 * @return 商品相关信息
	 * @author luoyzh 823884124@qq.com
	 */
	@RequestMapping(value = "getGoodsInfoDetail")
	@ResponseBody
	public RequestJson getGoodsInfoDetail(String goodsId , String token) {
		RequestJson result = new RequestJson();
		
		CommonToken commonToken = commonTokenService.selectByToken(token);
        // 根据token查询登录名
        String loginname = commonToken.getAccount();
        // 根据登录名查询用户
        User user = ouserService.selectByLoginName(loginname);
        // 根据用户查询业主ID
        String ownerId = user.getId();

        // 判断商品是否已经收藏
        GoodsCollection goodsCollection = goodsCollectionService
                .getGoodsCollectionByOwnerIdAndGoodsId(ownerId, goodsId);
		
		GoodsInfo goodsInfo = null;
		GoodsComment goodsComment = null;
		ShopInfo shopInfo = null;
		try {
			goodsInfo = goodsInfoService.getGoodsInfoDetail(goodsId);
            //设置收藏状态
			if(goodsCollection != null) {
                goodsInfo.setIsCollection(OwnerConstants.IS_COLLECTION);
            } else {
                goodsInfo.setIsCollection(OwnerConstants.IS_NOT_COLLECTION);
            }
			List<GoodsSpecAttrNameValue> goodsSpecAttrNameValueList = goodsInfoService
					.getGoodsSpecAttrNameValueList(goodsId);
			List<String> list = goodsInfoService.getAttrNameList(goodsId);
			List<Map<String, Object>> goodsSpecList = new ArrayList<Map<String, Object>>();
			for (String name : list) {
				Map<String, Object> map = new HashMap<String, Object>();
				List<Map<String, Object>> attrValueList = new ArrayList<Map<String, Object>>();
				for (GoodsSpecAttrNameValue nameValue : goodsSpecAttrNameValueList) {
					if (nameValue.getAttrName() != null
							&& nameValue.getAttrName().equals(name)) {
						Map<String, Object> mapValue = new HashMap<String, Object>();
						mapValue.put("attrValue", nameValue.getAttrValue());
						attrValueList.add(mapValue);
					}
				}
				map.put("attrValueList", attrValueList);
				map.put("attrName", name);
				goodsSpecList.add(map);
			}

			List<GoodsSpecification> specifiedGoodsInfo = goodsInfoService
					.getGoodsSpecWithValuesList(goodsId);
			List<CommonImg> commonImgList = goodsInfoService
					.getGoodsImgList(goodsId);
			goodsComment = goodsInfoService.getGoodsDetailOneComment(goodsId);
			int totalCommentNum = goodsInfoService.getGoodsCommentNum(goodsId);
			if (totalCommentNum != 0) {
				goodsComment.setTotalCommentNum(totalCommentNum);
			}
			String shopId = goodsInfoService.getShopId(goodsId);
			shopInfo = goodsInfoService.getShopInfo(shopId);
			List<GoodsInfo> recommendGoodsList = goodsInfoService
					.getRelatedGoodsRecommend(shopId, goodsId);
			Map<String, Object> mapAll = new HashMap<String, Object>();
			mapAll.put("goodsSpecList", goodsSpecList);// 该商品所有规格信息
			mapAll.put("goodsInfo", goodsInfo);// 商品基本信息
			mapAll.put("specifiedGoodsInfo", specifiedGoodsInfo);// 选好该商品各规格后的商品价格库存等信息
			mapAll.put("goodsComment", goodsComment);// 单条该商品评论
			mapAll.put("shopInfo", shopInfo);// 该商品对应的店铺信息
			mapAll.put("commonImgList", commonImgList);// 商品轮播图
			mapAll.put("recommendGoodsList", recommendGoodsList);// 该店铺里相关商品推荐
			mapAll.put("wapUrl", OwnerConstants.WAP_URL
					+ "/mall/getGoodsPicText?id=" + goodsId);// 该商品图文详情
			if (goodsInfo != null) {
				result.setSuccess(true);
				result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
				result.setMsg("数据获取成功！");
				result.setObj(mapAll);
			} 
		} catch (Exception e) {
			e.printStackTrace();
			result.setSuccess(false);
			result.setResultCode(OwnerConstants.GET_USERINFO_FALSE);
			result.setMsg("获取商品详情失败");
		}
		return result;
	}

	/**
	 * @Description 根据所选规格获取商品基本信息
	 * @param specificationId
	 * @return
	 * @author luoyzh 823884124@qq.com
	 * @data 2016年7月15日
	 */
	@RequestMapping(value = "getGoodsInfoBySpecId")
	@ResponseBody
	public RequestJson getGoodsInfoBySpecId(String specificationId) {
		RequestJson result = new RequestJson();
		GoodsSpecInfo goodsInfo = goodsInfoService
				.getGoodsInfoBySpecId(specificationId);
		if (goodsInfo != null) {
			result.setSuccess(true);
			result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
			result.setMsg("获取商品信息成功！");
			result.setObj(goodsInfo);
		} else {
			result.setResultCode(OwnerConstants.RESULT_EXCEPTION_FALSE);
			result.setMsg("获取商品信息失败！");
		}
		return result;
	}

	/**
	 * @Description 获取商品全部评价列表
	 * @param goodsId
	 *            商品id
	 * @param pNo
	 *            页数
	 * @return 商品评价list
	 * @author luoyzh 823884124@qq.com
	 * @data 2016年7月12日
	 */
	@RequestMapping(value = "getAllGoodsCommentList")
	@ResponseBody
	public RequestJson getAllGoodsCommentList(String goodsId, Integer pNo) {
		RequestJson result = new RequestJson();
		// 指定默认为首页
		if (pNo == null || pNo < OwnerConstants.PAGE_NO) {
			pNo = OwnerConstants.PAGE_NO;
		}
		// 此处添加PageHelper将会走拦截器，进行分页，分页方法只针对紧跟着PageHelper的查询方法有效
		PageHelper.startPage(pNo, Constants.PAGE_SIZE);
		List<GoodsComment> allGoodsCommentList = goodsInfoService
				.getGoodsDetailAllComment(goodsId);
		PageInfo<GoodsComment> allGoodsCommentListP = new PageInfo<GoodsComment>(
				allGoodsCommentList);
		if (!allGoodsCommentList.isEmpty() && (allGoodsCommentList.size() > 0)) {
			result.setSuccess(true);
			result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
			result.setMsg("获取商品评价列表成功！");
			result.setObj(allGoodsCommentListP);
		} else {
			result.setResultCode(OwnerConstants.RESULT_EXCEPTION_FALSE);
			result.setMsg("获取商品评价列表失败！");
		}
		return result;
	}

	/**
	 * @Description 获取购物车商品列表
	 * @param token
	 * @return 购物车商品list
	 * @author luoyzh 823884124@qq.com
	 * @data 2016年7月15日
	 */
	@RequestMapping(value = "getShoppingCartInfoList")
	@ResponseBody
	public RequestJson getShoppingCartInfoList(String token, Integer pNo,
			String cellId) {
		RequestJson result = new RequestJson();
		CommonToken commonToken = commonTokenService.selectByToken(token);
		// 指定默认为首页
		if (pNo == null || pNo < OwnerConstants.PAGE_NO) {
			pNo = OwnerConstants.PAGE_NO;
		}
		// 根据token查询登录名
		String loginname = commonToken.getAccount();
		try {
			List<ShopInfo> shoppingCartsList = goodsInfoService
					.getShoppingCartInfoList(loginname, cellId);
			if (!shoppingCartsList.isEmpty() && (shoppingCartsList.size() > 0)) {
				result.setSuccess(true);
				result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
				result.setMsg("获取购物车商品列表成功！");
				result.setObj(shoppingCartsList);
			} else {
				result.setSuccess(false);
				result.setResultCode(OwnerConstants.RESULT_EXCEPTION_FALSE);
				result.setMsg("无数据！");
			}
		} catch (Exception e) {
			result.setSuccess(false);
			result.setResultCode(OwnerConstants.GET_USERINFO_FALSE);
			result.setMsg("网络异常");
		}
		return result;
	}

	/**
	 * @Method: getShopGoodsInfo
	 * @Description 获取店铺商品信息（二级菜单目录下）
	 * @param goodsCategoryId
	 *            商品分类id shopId 店铺id
	 * @return result
	 * @author yangfan 373188993@qq.com
	 * @date 2016年7月12日
	 * @see
	 */
	@RequestMapping(value = "getShopGoodsInfo")
	@ResponseBody
	public RequestJson getShopGoodsInfo(String goodsCategoryId, String shopId,
			Integer pNo) {

		RequestJson result = new RequestJson();
		GoodsInfo goodsInfo = new GoodsInfo();

		try {
		    // 指定默认为首页
		    if (pNo == null || pNo < OwnerConstants.PAGE_NO) {
		        pNo = OwnerConstants.PAGE_NO;
		    }
		    
		    // goodsCategoryId为空则不设置为晒选条件， 默认为热销商品
		    if (null != goodsCategoryId) {
		        goodsInfo.setGoodsCategoryId(goodsCategoryId);
		    }
		    goodsInfo.setShopId(shopId);
		    
		    // 此处添加PageHelper将会走拦截器，进行分页，分页方法只针对紧跟着PageHelper的查询方法有效
		    PageHelper.startPage(pNo, Constants.PAGE_SIZE);
		    List<GoodsInfo> goodsInfoList = goodsInfoService
		        .selectGoodsInfoByKeyWords(goodsInfo);
		    PageInfo<GoodsInfo> goodsInfoListP = new PageInfo<GoodsInfo>(
		        goodsInfoList);
		    if (!goodsInfoList.isEmpty()) {
		        result.setSuccess(true);
		        result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
		        result.setMsg("获取店铺商品成功！");
		        result.setObj(goodsInfoListP);
		    } else {
		        result.setSuccess(false);
		        result.setResultCode(OwnerConstants.RESULT_EXCEPTION_FALSE);
		        result.setMsg("无数据！");
		    }
        } catch (Exception e) {
            result.setSuccess(false);
            result.setResultCode(OwnerConstants.RESULT_EXCEPTION_FALSE);
            result.setMsg("网络异常");
        }
		return result;
	}

	/**
	 * @Description 返回商品图文详情页面<br>
	 * 
	 * @param model
	 * @param id
	 *            商品id
	 * @return 返回商品图文详情页面
	 * @author caiyinli 13277030520@163.com
	 * @date 2016年7月18日
	 * @see
	 */
	@RequestMapping(value = "getGoodsPicText")
	public String getGoodsPicDetail(Model model, String id) {

		try {
			GoodsInfo goodsInfo = goodsInfoService.getGoodsInfoByPrimaryKey(id);
			model.addAttribute("goods", goodsInfo);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "goods/goodsDetail";
	}

	/**
	 * @Description 获取商城首页秒杀专区<br>
	 * 
	 * @param goodsCategoryId
	 * @param shopId
	 * @return
	 * @author caiyinli 13277030520@163.com
	 * @date 2016年7月18日
	 * @see
	 */
	@RequestMapping(value = "getSecKillGoods")
	@ResponseBody
	public RequestJson getSecKillGoods() {

		RequestJson result = new RequestJson();

		try {
			// 秒杀专区
			List<GoodsInfo> secKillGoods = goodsInfoService
					.getSecKillGoodsList();
			if (CollectionUtils.isNotEmpty(secKillGoods)) {
				for (GoodsInfo goodsInfo : secKillGoods) {
					goodsInfo.setLogo(Globals.getImageUrl()
							+ goodsInfo.getLogo());
				}
				result.setSuccess(true);
				result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
				result.setMsg("数据获取成功！");
				result.setObj(secKillGoods);
			}
		} catch (Exception e) {
			result.setSuccess(false);
			result.setResultCode(OwnerConstants.GET_USERINFO_FALSE);
			result.setMsg("网络异常！");
		}
		return result;
	}

	/**
	 * @Description 获取商城首页banner图<br>
	 * 
	 * @return 返回商城首页banner图
	 * @author caiyinli 13277030520@163.com
	 * @date 2016年7月28日
	 * @see
	 */
	@RequestMapping(value = "getSmallPic")
	@ResponseBody
	public RequestJson getSmallPic() {

		RequestJson result = new RequestJson();

		try {
			// 查询首页小图标
			AppConfig appConfig = new AppConfig();
			appConfig.setObjType(OwnerConstants.MALL_IMG);
			List<AppConfig> imgList = appConfigService
					.getAppConfigByKeyword(appConfig);
			if (CollectionUtils.isNotEmpty(imgList)) {
				for (AppConfig item : imgList) {
					item.setImgUrl(Globals.getImageUrl() + item.getImgUrl());
				}
			}
			result.setSuccess(true);
			result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
			result.setMsg("数据获取成功！");
			result.setObj(imgList);
		} catch (Exception e) {
			result.setSuccess(false);
			result.setResultCode(OwnerConstants.GET_USERINFO_FALSE);
			result.setMsg("网络异常！");
		}
		return result;
	}
}
